﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ElectronicsMarket.Service.IService;
using ElectronicsMarket.Service.Models;

namespace ElectronicsMarket.Service.ServiceImpl
{
    public class InventoryServiceImpl : IInventoryService
    {
        private ElectronicsMarketDBClassesDataContext eMEntity;

        public InventoryServiceImpl()
        {
            eMEntity = new ElectronicsMarketDBClassesDataContext();
        }
        public int getQuantityOfProduct(long productId)
        {
            INVENTORY inventory = eMEntity.INVENTORies.Where(p => p.INVENTORY_PRODUCT_ID == productId).FirstOrDefault();
            try
            {
                return inventory.INVENTORY_AMOUNT.Value;
            }
            catch
            {
                return 0;
            }
        }
    }
}